package com.szt.mobile.inventory.common.utils;

import android.content.Context;

import com.szt.mobile.inventory.common.entity.AccountDao;
import com.szt.mobile.inventory.common.entity.AssetsDao;
import com.szt.mobile.inventory.common.entity.AssetsListDao;
import com.szt.mobile.inventory.common.entity.DaoMaster;
import com.szt.mobile.inventory.common.entity.DaoSession;
import com.szt.mobile.inventory.common.entity.InventoryDao;

import org.greenrobot.greendao.identityscope.IdentityScopeType;

/**
 * Created by yanzhaodi on 2017/9/14.
 */
public class DBUtil {

    public static DaoSession getDaoSession(Context context, String dbName) {
        DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(context.getApplicationContext(), dbName + ".db", null);
        DaoMaster daoMaster = new DaoMaster(devOpenHelper.getWritableDb());
        return daoMaster.newSession(IdentityScopeType.None);
    }

    public static AssetsDao getAssetsDao(Context context) {
        DaoSession daoSession = getDaoSession(context, CacheUtil.getCacheUserName());
        return daoSession.getAssetsDao();
    }

    public static InventoryDao getInventoryDao(Context context) {
        DaoSession daoSession = getDaoSession(context, CacheUtil.getCacheUserName());
        return daoSession.getInventoryDao();
    }

    public static AssetsListDao getAssetsListDao(Context context) {
        DaoSession daoSession = getDaoSession(context, CacheUtil.getCacheUserName());
        return daoSession.getAssetsListDao();
    }

    public static AccountDao getAccountDao(Context context) {
        DaoSession daoSession = getDaoSession(context, "common");
        return daoSession.getAccountDao();
    }
}
